<!doctype html>
<html>

<head>
	<title></title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<link rel="stylesheet" href="../res/css/weui.css" />
	<link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css" />
	<script src="../res/js/zepto.min.js"></script>
	<script src="../res/js/zepto.weui.js"></script>
	<script src="../res/js/common.js?v=1"></script>
	<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
	<script src="" type="text/javascript" charset="utf-8"></script>
	<script>
		var tipMessageList = {
			chMedicine: ["一般病症每日服一剂，每剂二煎或三煎，分两次（早、晚各1次）送服或三次（早、中、晚各1次）送服，每次服用约200ml。急症、高热和危重病人酌情每日2~3剂或遵医嘱。", "用法请遵循医嘱"],
			weMedicine: ["一般可用白开水送服，特殊送服方法请遵循医嘱。", "用法请参考药品说明书或遵循医嘱！"]
		}

		function getDrug() {
			var paramJson = {
				"id": order_id,
			};
			console.log(paramJson);
			newAjaxPost("/h5/medicalRecord/getPrescriptionDrugDetail", paramJson, getDrugOK);
			return false;
		}

		function getDrugOK(jsonInfo) {
			let data = [];
			let commitList = [];
			let prescriptionType = "";
			if (jsonInfo.code == "1") {
				data = jsonInfo.data.prescriptionDrugListResps;
				prescriptionType = data[0].prescriptionType
				if (prescriptionType == 2) {
					if (data.length > 0) {
						for (var i = 0; i < data.length; i++) {
							// console.log(data[i]);
							commitList += `<div>`
							commitList += `<div class="messageTop">`
							if (data[i].drugImg) {
								commitList += `<img src=${data[i].drugImg} alt="">`
							} else {
								commitList += `<img src="../res/images/img_drugs@2x.png" alt="">`
							}
							commitList += `<div>`
							commitList += `<span>${data[i].drugName}</span>`
							commitList +=
								`<p><span>${data[i].drugSpecifications}</span><span style="margin-left:60%">×${data[i].detailsNum}</span></p>`
							commitList += `</div>`
							commitList += `</div>`
							commitList += `<div class="messageBody">`
							commitList += `<div class="useage">`
							commitList += `<div>用法用量:</div>`
							commitList +=
								`<div> ${data[i].detailsUsage} ${data[i].detailsFrequencyStr} 每次${data[i].detailsConsumption}${data[i].detailsConsumptionUnit}</div>`
							commitList += `</div>`
							commitList += `<div class="useage">`
							commitList += `<div>注意事项:</div>`
							if (data[i].detailsEntrust) {
								commitList += `<div>${data[i].detailsEntrust}</div>`
							} else {
								commitList += `<div>无</div>`
							}
							commitList += `</div>`
							commitList += `</div>`
							commitList += `</div>`

						}
					} else {
						commitList += '<div class="info_content" style="text-align:center">暂无药品</div>'
					}
				} else {
					if (data.length > 0) {
						commitList += `<div class="chMedList">`
						for (var i = 0; i < data.length; i++) {
							commitList +=
								`<div>${data[i].drugName}${data[i].detailsConsumption}${data[i].detailsConsumptionUnit}<p>${data[i].detailsUsage}</p></div>`
						}
						commitList += `</div>`
						commitList += `<div class="messageBody">`
						commitList += `<div class="useages">`
						commitList += `<div>[${data[0].prescriptionTaking},${data[0].prescriptionRequirements}]</div>`
						commitList += `<div>共 ${data[0].prescriptionNum} 付</div>`
						commitList += `</div>`
						commitList += `</div>`
					} else {
						commitList += '<div class="info_content" style="text-align:center">暂无药品</div>'
					}
				}
			} else {
				msgInfo(jsonInfo.msg)
			}
			commitList += `<div class="tip">`
			commitList += `<div>温馨提示:</div>`
			// console.log(data[0].prescriptionTaking);
			var message = ""
			if (prescriptionType == 1) {
				data.forEach(element => {
					console.log(element.detailsUsage);
					if (element.detailsUsage.indexOf('水煎') != -1) {
						message = `<div>${tipMessageList.chMedicine[0]}</div>`
					} else {
						message = `<div>${tipMessageList.chMedicine[1]}</div>`
					}
				});
			} else {
				data.forEach(element => {
					console.log(element.detailsUsage);
					if (element.detailsUsage.indexOf('口服') != -1) {
						message = `<div>${tipMessageList.weMedicine[1]}</div>`
					}
					else{
						message=`<div>${tipMessageList.weMedicine[0]}</div>`
						return;
					}
				});
			}
			commitList += message
			commitList += `<div>祝您早日康复！</div>`
			commitList += `</div>`
			$('.block').html(commitList);
		}


		$(function () {
			order_id = getQst('id')
			getDrug()
			$('#btnBack').on("click", function () {
				history.go(-1);
			});
		});
	</script>
	<style>
		.fixed-top {
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 5;
		}

		.weui-btn_primary:not(.weui-btn_disabled):active {
			background-color: #ffffff;
		}

		.weui-btn_primary {
			background-color: #ffffff;
		}

		.block {
			width: 95%;
			margin: 10px 2.5%;
		}

		.lists {
			margin-top: 60px;
		}

		.messageTop {
			width: 90%;
			margin: 10px 5%;
			display: flex;
		}

		.messageTop img {
			width: 58px;
			height: 58px;
			margin: 5px;
		}

		.messageTop span {
			margin: 5px 10px;
			display: inline-block;
			font-size: 14px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #353535;

		}

		.messageTop>div {
			width: 80%;
		}

		.messageBody {
			width: 90%;
			margin: 10px 5%;
			background: #FBFBFB;
			border-radius: 10px;
			overflow: hidden;
		}

		.messageBody .useage {
			display: flex;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			margin: 15px 10px;
		}

		.messageBody .useages {
			display: flex;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			margin: 15px 10px;
		}

		.messageBody .useage div:nth-child(1) {
			width: 25%;
			color: #757575;
		}

		.messageBody .useage div:nth-child(2) {
			width: 75%;
			color: #353535;
		}

		.messageBody .useages div:nth-child(1) {
			width: 35%;
			color: #757575;
		}

		.messageBody .useages div:nth-child(2) {
			width: 60%;
			color: #353535;
			text-align: right;
			margin-right: 30px;
		}

		.tip {
			width: 90%;
			margin: 10px 5%;
			font-size: 14px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #757575;
			line-height: 30px;
		}

		.tip div:nth-child(3) {
			text-align: right;
			color: #228E3A;
		}

		.chMedList {
			display: flex;
			flex-direction: column;
		}

		.chMedList div {
			width: 40%;
			margin: 10px 5%;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #353535;
		}

		.chMedList span {
			margin-left: 10px;
		}
	</style>

<body ontouchstart>
	<div class="fixed-top">
		<div class="weui-header weui-btn_primary">
			<div class="weui-header-left"><a id="btnBack" class="icon icon-109"></a></div>
			<div class="weui-header-title">用药详情</div>
			<div class="weui-header-right"></div>
		</div>
	</div>
	<div class="lists">
		<div class="block weui-cells">
		</div>
</body>

</html>